//
//  UserSetting.m
//  掌上海印
//
//  Created by 陈德锋 on 16/4/18.
//  Copyright © 2016年 handsome. All rights reserved.
//

#import "UserSetting.h"
#import "imagecell.h"
#import "labelcell.h"
#import "QRcedeView.h"
#import "EditController.h"

@interface UserSetting ()
@property (nonatomic, strong) labelcell *cell;
@end

@implementation UserSetting

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.leftBarButtonItem = nil;
    self.view.backgroundColor = [UIColor colorWithRed:246.0/255.0 green:246.0/255.0 blue:246.0/255.0 alpha:1.0];
    self.tableView.frame = CGRectMake(0, 0, [[UIScreen mainScreen]bounds].size.width, [[UIScreen mainScreen]bounds].size.height);
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 0.1;
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    self.tabBarController.tabBar.hidden = NO;
}

-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0) {
        return 4;
    }else if (section ==1)
    {
        return 3;
    }
    else
    {
        return 1;
    }
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 3;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0 ) {
        if (indexPath.row == 0) {
            imagecell *newcell = [imagecell imagecellWithTableView:tableView];
            newcell.icon.image = [UIImage imageNamed:@"001.jpg"];
            newcell.textLabel.text = @"头像";
            newcell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
            return newcell;
        }else if (indexPath.row ==1){
            _cell = [labelcell labelcellWithTableView:tableView];
            _cell.textLabel.text = @"姓名";
            _cell.label.text = @"黄海成";
            return _cell;
        }else if (indexPath.row ==2){
            _cell = [labelcell labelcellWithTableView:tableView];
            _cell.textLabel.text = @"性别";
            _cell.label.text = @"未设置";
            _cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
            return _cell;
        }else{
            _cell = [labelcell labelcellWithTableView:tableView];
            _cell.textLabel.text = @"二维码名片";
            _cell.icon.image = [UIImage imageNamed:@"qrcode"];
            _cell.label.hidden = YES;
            _cell.icon.hidden = NO;
            _cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
            return _cell;
        }
        
    }else if (indexPath.section ==1){
        if (indexPath.row ==0){
            _cell = [labelcell labelcellWithTableView:tableView];
            _cell.textLabel.text = @"公司";
            _cell.label.text = @"海印集团";
            return _cell;
        }else if (indexPath.row ==1){
            _cell = [labelcell labelcellWithTableView:tableView];
            _cell.textLabel.text = @"部门";
            _cell.label.text = @"未设置";
            _cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
            return _cell;
        }else{
            _cell = [labelcell labelcellWithTableView:tableView];
            _cell.textLabel.text = @"职位";
            _cell.label.text = @"未设置";
            _cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
            return _cell;
        }
    
    }
    else
    {
        labelcell *cell = [labelcell labelcellWithTableView:tableView];
        cell.textLabel.text = @"手机";
        cell.label.text = @"18814129437";
        return cell;
    }
    return nil;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section ==0) {
        return 10;
    }
    else{
        
        return 20;
    }
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section ==0) {
        if (indexPath.row ==0) {
            return 70;
        }else{
            return 45;
        }
    }
    else{
        return 45;
    }
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.section ==0) {
        if (indexPath.row ==0) {
            
            UIAlertController *actionsheetController = [[UIAlertController alloc]init];
            UIAlertAction *canceAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action){
            }];
            UIAlertAction *phoneAction = [UIAlertAction actionWithTitle:@"相册" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action){

            }];
            UIAlertAction *messageAction = [UIAlertAction actionWithTitle:@"拍照" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action){
                
            }];
            [actionsheetController addAction: canceAction];
            [actionsheetController addAction:phoneAction];
            [actionsheetController addAction:messageAction];
            [self presentViewController:actionsheetController animated:true completion:nil];

            
        }else if (indexPath.row ==1){
        
        }else if (indexPath.row ==2){
          
            UIAlertController *actionsheetController = [[UIAlertController alloc]init];
            UIAlertAction *canceAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action){
            }];
            UIAlertAction *phoneAction = [UIAlertAction actionWithTitle:@"男" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action){
                _cell.label1.text = @"男";
                
            }];
            UIAlertAction *messageAction = [UIAlertAction actionWithTitle:@"女" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action){
                _cell.label.text = @"女";
            }];
            [actionsheetController addAction: canceAction];
            [actionsheetController addAction:phoneAction];
            [actionsheetController addAction:messageAction];
            [self presentViewController:actionsheetController animated:true completion:nil];
        
        }else{
            [self.navigationController pushViewController:[[QRcedeView alloc]init] animated:YES];
        }
    }
    else if (indexPath.section ==1){
        if (indexPath.row ==0) {
            
        }else if (indexPath.row ==1){
            UIAlertController *actionsheetController = [[UIAlertController alloc]init];
            UIAlertAction *canceAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action){
            }];
            UIAlertAction *phoneAction = [UIAlertAction actionWithTitle:@"添加部门" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action){
                
            }];
            UIAlertAction *messageAction = [UIAlertAction actionWithTitle:@"加入部门" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action){
                
            }];
            [actionsheetController addAction: canceAction];
            [actionsheetController addAction:phoneAction];
            [actionsheetController addAction:messageAction];
            [self presentViewController:actionsheetController animated:true completion:nil];
        
        }else{
            [self.navigationController pushViewController:[[EditController alloc]init] animated:YES];
        }
    }else{
    
    
    }
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
}
@end
